home *** CD-ROM | disk | FTP | other *** search
/ Champak 62 / Volume 62 - JOGO DISK .iso / Games / missioncandy.swf / scripts / frame_1 / DoAction.as
Text File  |  2008-03-17  |  16KB  |  576 lines

  1. function goGame()
  2. {
  3.    stopAllSounds();
  4.    gotoAndStop("GAME1");
  5.    play();
  6. }
  7. function goIntro()
  8. {
  9.    stopAllSounds();
  10.    gotoAndStop("INTRO");
  11.    play();
  12. }
  13. function goEnding()
  14. {
  15.    stopAllSounds();
  16.    gotoAndStop("ENDING");
  17.    play();
  18. }
  19. function goHowto()
  20. {
  21.    gotoAndStop("HOWTO");
  22.    play();
  23. }
  24. function initGmae()
  25. {
  26.    game_start = true;
  27.    gof = 4 - m_life;
  28.    life_mc.gotoAndStop(gof);
  29.    sBuf = 0;
  30.    charSpeed = 5;
  31.    lastLR = 3;
  32.    char_mc.goX = char_mc._x;
  33.    ground2_mc.goX = ground2_mc._x;
  34.    keyAction = 0;
  35.    jumpFr = 0;
  36.    char_mc.incomming = false;
  37.    char_mc.incommingLmt = 90;
  38.    char_mc.incommingCnt = 0;
  39.    char_mc.lampLmt = 2;
  40.    char_mc.lmapCnt = 0;
  41.    this.onEnterFrame = function()
  42.    {
  43.       if(game_start == true)
  44.       {
  45.          updateScore();
  46.          if(char_mc.incomming == true)
  47.          {
  48.             char_mc.incommingCnt = char_mc.incommingCnt + 1;
  49.             if(char_mc.incommingCnt < char_mc.incommingLmt)
  50.             {
  51.                if(char_mc.lampCnt == 0)
  52.                {
  53.                   if(char_mc._alpha == 100)
  54.                   {
  55.                      char_mc._alpha = 50;
  56.                   }
  57.                   else
  58.                   {
  59.                      char_mc._alpha = 100;
  60.                   }
  61.                }
  62.                if(char_mc.lampCnt < char_mc.lampLmt)
  63.                {
  64.                   char_mc.lampCnt = char_mc.lampCnt + 1;
  65.                }
  66.                else
  67.                {
  68.                   char_mc.lampCnt = 0;
  69.                }
  70.             }
  71.             else
  72.             {
  73.                char_mc.incommingCnt = 0;
  74.                char_mc.incomming = false;
  75.                char_mc._alpha = 100;
  76.             }
  77.          }
  78.          if(Key.isDown(37))
  79.          {
  80.             if(keyAction == 0 or keyAction == 1 or keyAction == 2)
  81.             {
  82.                keyAction = 1;
  83.             }
  84.          }
  85.          if(Key.isDown(39))
  86.          {
  87.             if(keyAction == 0 or keyAction == 1 or keyAction == 2)
  88.             {
  89.                keyAction = 2;
  90.             }
  91.          }
  92.          if(Key.isDown(38))
  93.          {
  94.             if(keyAction == 0 or keyAction == 1 or keyAction == 2)
  95.             {
  96.                jumpSnd_mc.gotoAndPlay(2);
  97.                jumpFr = 0;
  98.                jumpYspeed = -13;
  99.                if(keyAction == 0)
  100.                {
  101.                   jumpAction(0);
  102.                }
  103.                if(keyAction == 1)
  104.                {
  105.                   jumpAction(- charSpeed);
  106.                }
  107.                if(keyAction == 2)
  108.                {
  109.                   jumpAction(charSpeed);
  110.                }
  111.             }
  112.          }
  113.          if(Key.isDown(32))
  114.          {
  115.             if(keyAction == 0 or keyAction == 1 or keyAction == 2)
  116.             {
  117.                keyAction = 4;
  118.             }
  119.          }
  120.          if(keyAction == 1)
  121.          {
  122.             if(char_mc.goX >= char_mc._x)
  123.             {
  124.                if(char_mc._currentframe != 4)
  125.                {
  126.                   char_mc.gotoAndStop(4);
  127.                }
  128.                if(char_mc._x - charSpeed < stageWidth / 2 and ground2_mc._x + charSpeed < 0)
  129.                {
  130.                   ground2_mc.goX = ground2_mc._x + charSpeed;
  131.                   balanceGround();
  132.                }
  133.                else
  134.                {
  135.                   char_mc.goX = char_mc._x - charSpeed;
  136.                }
  137.                lastLR = 4;
  138.                if(ground_mc.hitTest(char_mc._x,char_mc._y + 1,true) == false and ground2_mc.hitTest(char_mc._x,char_mc._y + 1,true) == false)
  139.                {
  140.                   jumpFr = 0;
  141.                   jumpYspeed = 10;
  142.                   jumpAction(0);
  143.                }
  144.                else
  145.                {
  146.                   keyAction = 0;
  147.                }
  148.             }
  149.          }
  150.          else if(keyAction == 2)
  151.          {
  152.             if(char_mc.goX <= char_mc._x)
  153.             {
  154.                if(char_mc._currentframe != 3)
  155.                {
  156.                   char_mc.gotoAndStop(3);
  157.                }
  158.                if(char_mc._x + charSpeed >= stageWidth / 2 and ground2_mc._x - charSpeed > stageWidth - ground2_mc._width)
  159.                {
  160.                   ground2_mc.goX = ground2_mc._x - charSpeed;
  161.                   balanceGround();
  162.                }
  163.                else
  164.                {
  165.                   char_mc.goX = char_mc._x + charSpeed;
  166.                }
  167.                lastLR = 3;
  168.                if(ground_mc.hitTest(char_mc._x,char_mc._y + 1,true) == false and ground2_mc.hitTest(char_mc._x,char_mc._y + 1,true) == false)
  169.                {
  170.                   jumpFr = 0;
  171.                   jumpYspeed = 10;
  172.                   jumpAction(0);
  173.                }
  174.                else
  175.                {
  176.                   keyAction = 0;
  177.                }
  178.             }
  179.          }
  180.          else if(keyAction == 3)
  181.          {
  182.             if(char_mc._x + jumpXspeed >= stageWidth / 2 and jumpXspeed > 0 and ground2_mc._x - charSpeed > stageWidth - ground2_mc._width)
  183.             {
  184.                ground2_mc.goX -= charSpeed;
  185.             }
  186.             else if(char_mc._x + jumpXspeed <= stageWidth / 2 and jumpXspeed < 0 and ground2_mc._x + charSpeed < 0)
  187.             {
  188.                ground2_mc.goX += charSpeed;
  189.             }
  190.             else if(char_mc._x + charSpeed > stageWidth and ground2_mc._x - charSpeed <= stageWidth - ground2_mc._width)
  191.             {
  192.                char_mc._x = stageWidth;
  193.             }
  194.             else if(char_mc._x - charSpeed < 0)
  195.             {
  196.                char_mc._x = 0;
  197.             }
  198.             else
  199.             {
  200.                char_mc._x += jumpXspeed;
  201.             }
  202.             char_mc.goX = char_mc._x;
  203.             if(jumpYspeed > 10)
  204.             {
  205.                jumpYspeed = 10;
  206.             }
  207.             char_mc._y += jumpYspeed;
  208.             jumpYspeed += 1;
  209.             if(jumpYspeed > 0)
  210.             {
  211.                if(ground_mc.hitTest(char_mc._x,char_mc._y + jumpYspeed,true))
  212.                {
  213.                   tempY = Math.round(char_mc._y + jumpYspeed);
  214.                   nQuit = true;
  215.                   while(nQuit)
  216.                   {
  217.                      tempY--;
  218.                      if(ground_mc.hitTest(char_mc._x,tempY,true) == false)
  219.                      {
  220.                         tempY++;
  221.                         nQuit = false;
  222.                      }
  223.                   }
  224.                   char_mc._y = tempY;
  225.                   keyAction = 0;
  226.                }
  227.                else if(ground2_mc.hitTest(char_mc._x,char_mc._y + jumpYspeed,true))
  228.                {
  229.                   tempY = Math.round(char_mc._y + jumpYspeed);
  230.                   nQuit = true;
  231.                   while(nQuit)
  232.                   {
  233.                      tempY--;
  234.                      if(ground2_mc.hitTest(char_mc._x,tempY,true) == false)
  235.                      {
  236.                         tempY++;
  237.                         nQuit = false;
  238.                      }
  239.                   }
  240.                   char_mc._y = tempY;
  241.                   keyAction = 0;
  242.                }
  243.                else
  244.                {
  245.                   char_mc._y += jumpYspeed;
  246.                }
  247.             }
  248.             jumpFr += 1;
  249.          }
  250.          else if(keyAction == 4)
  251.          {
  252.             standChar();
  253.          }
  254.          else
  255.          {
  256.             if(lastLR == 3 and keyAction != 5)
  257.             {
  258.                char_mc.gotoAndStop(1);
  259.             }
  260.             if(lastLR == 4 and keyAction != 5)
  261.             {
  262.                char_mc.gotoAndStop(2);
  263.             }
  264.          }
  265.          if(ground2_mc.goX < ground2_mc._x)
  266.          {
  267.             ground2_mc._x -= charSpeed;
  268.             balanceGround();
  269.             allMonsterMove(- charSpeed);
  270.             allEatMove(- charSpeed);
  271.          }
  272.          if(ground2_mc.goX > ground2_mc._x)
  273.          {
  274.             ground2_mc._x += charSpeed;
  275.             balanceGround();
  276.             allMonsterMove(charSpeed);
  277.             allEatMove(charSpeed);
  278.          }
  279.          if(char_mc.goX > char_mc._x)
  280.          {
  281.             if(char_mc._x + charSpeed > stageWidth and ground2_mc._x - charSpeed <= stageWidth - ground2_mc._width)
  282.             {
  283.                char_mc._x = stageWidth;
  284.                char_mc.goX = stageWidth;
  285.             }
  286.             else
  287.             {
  288.                char_mc._x += charSpeed;
  289.             }
  290.          }
  291.          if(char_mc.goX < char_mc._x)
  292.          {
  293.             if(char_mc._x - charSpeed < 0)
  294.             {
  295.                char_mc._x = 0;
  296.                char_mc.goX = 0;
  297.             }
  298.             else
  299.             {
  300.                char_mc._x -= charSpeed;
  301.             }
  302.          }
  303.          if(Math.abs(char_mc.goX - char_mc._x) < charSpeed)
  304.          {
  305.             char_mc.goX = Math.round(char_mc.goX);
  306.             char_mc._x = Math.round(char_mc.goX);
  307.          }
  308.          if(end_mc.hitTest(char_mc._x,char_mc._y - char_mc._height,true))
  309.          {
  310.             if(Number(eat_txt.text) == 0)
  311.             {
  312.                game_start = false;
  313.                pause_mc.gotoAndStop(1);
  314.                pauseBtn_mc.gotoAndStop(1);
  315.                clear_mc.gotoAndPlay(2);
  316.             }
  317.             else if(eatDsp_mc._currentframe == 1)
  318.             {
  319.                eatDsp_mc.gotoAndPlay(2);
  320.             }
  321.          }
  322.       }
  323.    };
  324. }
  325. function eatAI(ms_mc)
  326. {
  327.    eat_array[eat_array.length] = ms_mc;
  328.    ms_mc.onEnterFrame = function()
  329.    {
  330.       if(this.hitTest(char_mc._x,this._y,true) and Math.abs(char_mc._y - this._y) < char_mc._height / 2 and this._currentframe == 1)
  331.       {
  332.          this.gotoAndPlay(2);
  333.          i = 0;
  334.          while(i < eat_array.length)
  335.          {
  336.             if(eat_array[i] == this)
  337.             {
  338.                eat_array.splice(i,1);
  339.                i = eat_array.length + 2;
  340.                update_eat();
  341.             }
  342.             i++;
  343.          }
  344.       }
  345.    };
  346.    update_eat();
  347. }
  348. function update_eat()
  349. {
  350.    if(eat_array.length < 10)
  351.    {
  352.       eat_txt.text = "0" + eat_array.length;
  353.    }
  354.    else
  355.    {
  356.       eat_txt.text = eat_array.length;
  357.    }
  358. }
  359. function allEatMove(mSpeed)
  360. {
  361.    i = 0;
  362.    while(i < eat_array.length)
  363.    {
  364.       eat_array[i]._x += mSpeed;
  365.       i++;
  366.    }
  367. }
  368. function monsterAI1(ms_mc, getSpeed)
  369. {
  370.    monster_array[monster_array.length] = ms_mc;
  371.    ms_mc.mSpeed = getSpeed;
  372.    gof = Math.floor(Math.random() * 2) + 1;
  373.    ms_mc.eng = 2;
  374.    ms_mc.gotoAndStop(gof);
  375.    ms_mc.onEnterFrame = function()
  376.    {
  377.       if(game_start == true)
  378.       {
  379.          if(this._currentframe == 1)
  380.          {
  381.             if(ground2_mc.hitTest(this._x - 10,this._y + 5,true))
  382.             {
  383.                this._x -= this.mSpeed;
  384.             }
  385.             else
  386.             {
  387.                this.gotoAndStop(2);
  388.             }
  389.          }
  390.          if(this._currentframe == 2)
  391.          {
  392.             if(ground2_mc.hitTest(this._x + 10,this._y + 5,true))
  393.             {
  394.                this._x += this.mSpeed;
  395.             }
  396.             else
  397.             {
  398.                this.gotoAndStop(1);
  399.             }
  400.          }
  401.          if(char_mc.char_mc.fog_mc.hitTest(this._x,char_mc._y - char_mc._height / 2,true) and Math.abs(char_mc._y - this._y) < char_mc._height / 2 and this._currentframe != 5 and this._currentframe != 6)
  402.          {
  403.             if(char_mc._x < this._x)
  404.             {
  405.                this.gotoAndStop(3);
  406.             }
  407.             else
  408.             {
  409.                this.gotoAndStop(4);
  410.             }
  411.          }
  412.          else if(this.hit_mc.hitTest(char_mc) and Math.abs(char_mc._y - this._y) < char_mc._height / 2 and char_mc.incomming == false and (keyAction == 1 or keyAction == 2 or keyAction == 0))
  413.          {
  414.             char_mc.incomming = true;
  415.             if(lastLR == 3)
  416.             {
  417.                char_mc.gotoAndStop(9);
  418.             }
  419.             if(lastLR == 4)
  420.             {
  421.                char_mc.gotoAndStop(10);
  422.             }
  423.             keyAction = 5;
  424.          }
  425.       }
  426.    };
  427. }
  428. function monsterAI2(ms_mc, getSpeed)
  429. {
  430.    monster_array[monster_array.length] = ms_mc;
  431.    ms_mc.mSpeed = getSpeed;
  432.    ms_mc.gotoAndStop(2);
  433.    ms_mc.eng = 2;
  434.    ms_mc.onEnterFrame = function()
  435.    {
  436.       if(game_start == true)
  437.       {
  438.          if(Math.abs(this._x - char_mc._x) <= stageWidth and Math.abs(this._x - char_mc._x) > Math.abs(this.mSpeed) and (this._currentframe == 1 or this._currentframe == 2))
  439.          {
  440.             if(Math.abs(this._x - char_mc._x) <= this.mSpeed)
  441.             {
  442.                this._x = char_mc._x;
  443.             }
  444.             else if(this._x > char_mc._x)
  445.             {
  446.                this.mSpeed = Math.abs(this.mSpeed) * -1;
  447.                if(this._currentframe != 1)
  448.                {
  449.                   this.gotoAndStop(1);
  450.                }
  451.             }
  452.             else
  453.             {
  454.                this.mSpeed = Math.abs(this.mSpeed);
  455.                if(this._currentframe != 2)
  456.                {
  457.                   this.gotoAndStop(2);
  458.                }
  459.             }
  460.             this._x += this.mSpeed;
  461.          }
  462.          if(char_mc.char_mc.fog_mc.hitTest(this._x,char_mc._y - char_mc._height / 2,true) and Math.abs(char_mc._y - this._y) < char_mc._height / 2 and this._currentframe != 5 and this._currentframe != 6)
  463.          {
  464.             if(char_mc._x < this._x)
  465.             {
  466.                this.gotoAndStop(3);
  467.             }
  468.             else
  469.             {
  470.                this.gotoAndStop(4);
  471.             }
  472.          }
  473.          else if(this.hit_mc.hitTest(char_mc) and Math.abs(char_mc._y - this._y) < char_mc._height / 2 and char_mc.incomming == false and (keyAction == 1 or keyAction == 2 or keyAction == 0))
  474.          {
  475.             char_mc.incomming = true;
  476.             if(lastLR == 3)
  477.             {
  478.                char_mc.gotoAndStop(9);
  479.             }
  480.             if(lastLR == 4)
  481.             {
  482.                char_mc.gotoAndStop(10);
  483.             }
  484.             keyAction = 5;
  485.          }
  486.       }
  487.    };
  488. }
  489. function allMonsterMove(mSpeed)
  490. {
  491.    i = 0;
  492.    while(i < monster_array.length)
  493.    {
  494.       monster_array[i]._x += mSpeed;
  495.       i++;
  496.    }
  497. }
  498. function standChar()
  499. {
  500.    if(lastLR == 3 and char_mc._currentframe != 5)
  501.    {
  502.       char_mc.gotoAndStop(5);
  503.    }
  504.    if(lastLR == 4 and char_mc._currentframe != 6)
  505.    {
  506.       char_mc.gotoAndStop(6);
  507.    }
  508. }
  509. function jumpAction(xpd)
  510. {
  511.    if(keyAction == 0)
  512.    {
  513.       jumpXspeed = 0;
  514.    }
  515.    else if(keyAction == 1)
  516.    {
  517.       jumpXspeed = xpd;
  518.       char_mc.gotoAndStop(8);
  519.    }
  520.    else if(keyAction == 2)
  521.    {
  522.       jumpXspeed = xpd;
  523.       char_mc.gotoAndStop(7);
  524.    }
  525.    keyAction = 3;
  526. }
  527. function balanceGround()
  528. {
  529.    ground3_mc._x = ground2_mc._x;
  530.    ground_mc._x = ground2_mc._x;
  531.    a = (bg_mc._width - stageWidth) / (ground2_mc._width - stageWidth);
  532.    b = 1 - a * 0.5;
  533.    bg_mc._x = a * ground2_mc._x + b;
  534. }
  535. function updateScore()
  536. {
  537.    if(now_score < m_score)
  538.    {
  539.       scoreSnd_mc.gotoAndPlay(2);
  540.       now_score += 5;
  541.    }
  542.    if(now_score > m_score)
  543.    {
  544.       now_score = m_score;
  545.    }
  546.    m_score_str = String(now_score);
  547.    if(m_score_str.length == 3)
  548.    {
  549.       m_score_str = "0" + m_score_str;
  550.    }
  551.    if(m_score_str.length == 2)
  552.    {
  553.       m_score_str = "00" + m_score_str;
  554.    }
  555.    if(m_score_str.length == 1)
  556.    {
  557.       m_score_str = "000" + m_score_str;
  558.    }
  559.    var _loc2_ = 1;
  560.    while(_loc2_ < m_score_str.length + 1)
  561.    {
  562.       this.score_mc["num" + _loc2_].gotoAndStop(int(m_score_str.substr(_loc2_ - 1,1)) + 1);
  563.       _loc2_ = _loc2_ + 1;
  564.    }
  565. }
  566. stageWidth = 500;
  567. delete monster_array;
  568. delete eat_array;
  569. m_level = 1;
  570. monster_array = new Array();
  571. eat_array = new Array();
  572. m_score = 0;
  573. now_score = 0;
  574. m_life = 3;
  575. game_start = false;
  576.